import request from '../utils/request';

interface RootObject {
  'access-control-allow-credentials': string;
  'access-control-allow-origin': string;
  'access-control-expose-headers': string;
  connection: string;
  'content-encoding': string;
  'content-type': string;
  date: string;
  etag: string;
  success: string;
  'transfer-encoding': string;
  vary: string;
  'x-fc-code-checksum': string;
  'x-fc-instance-id': string;
  'x-fc-invocation-duration': string;
  'x-fc-invocation-service-version': string;
  'x-fc-max-memory-usage': string;
  'x-fc-request-id': string;
  'x-powered-by': string;
  'x-waf-access': string;
  'x-waf-client-ip': string;
}

interface Common<T> {
    code:string,
    mesg:string,
    time:string,
    data:T,
}
interface CoursesResult {
    records:Record[],
    total:number,
    size:number,
    current:number,
    
}
interface RootObject {
  code: string;
  data: Data;
  mesg: string;
  time: string;
}

interface Data {
  records: Record[];
  total: number;
  size: number;
  current: number;
  pages: number;
}

interface Record {
  id: number;
  courseName: string;
  price: string;
  sortNum: number;
  status: number;
}


export type QueryCondition = Partial<{
    currentPage: number,
    pageSize: number,
    courseName: string,
    status: number | ""
}>
//分页查询课程信息
export const getQueryCourses = (params: QueryCondition = {}) => {
    return request<Common<CoursesResult>>({
      method:'post',
      url:'/boss/course/getQueryCourses',
      data:params,
    })
}

//课程上下架
export const changeState = (courseId:number,status:number) => {
   return request<Common<Boolean>>({
   method:"get",
   url:"/boss/course/changeState",
   params:{courseId,status}
   })
}

interface Course {
  courseName: string;
  brief: string;
  teacherDTO: TeacherDTO;
  previewFistField: string;
  previewSecondField: string;
  sortNum: number;
  courseListImg: string;
  courseImgUrl: string;
  discounts: number;
  price: number;
  sales: number;
  discountTag: string;
  activityCourse: boolean;
  activityCourseDTO: ActivityCourseDTO;
}

interface ActivityCourseDTO {
  beginTime: string;
  endTime: string;
  amount: number;
  stock: number;
  courseDescriptionMarkDown: string;
  status: number;
}

interface TeacherDTO {
  teacherName: string;
  position: string;
  description: string;
}
//保存或更新课程信息
export const saveOrUpdateCourse = (course: Course) => {
  return request<Common<Boolean>>({
    method:"post",
    url:"/boss/course/saveOrUpdateCourse",
    data:course,
  })
}
//编辑  获取制定ID的课程信息
export const getCourseById = (courseId:string) => {
  return request<Common<Course>>({
    method:"get",
    url:"/boss/course/getCourseById",
    params:{courseId},
  })
}